package edu.whpu.sztz.action.file;

import java.io.InputStream;

import javax.annotation.Resource;

import com.opensymphony.xwork2.ActionSupport;

import edu.whpu.sztz.model.upload.UploadImage;
import edu.whpu.sztz.services.upload.UploadImageService;

public class FileDownloadAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6155213520470453413L;
	
	@Resource	private UploadImageService uploadImageService;
	
	private long id;
	private InputStream stream;
	
	private String contentType;
	
	@Override
	public String execute() throws Exception {
		UploadImage uploadImage = uploadImageService.get(id);
		this.contentType = uploadImage.getContentType();
		stream = uploadImage.getContent().getBinaryStream();
		return SUCCESS;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public InputStream getStream() {
		return stream;
	}

	public void setStream(InputStream stream) {
		this.stream = stream;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}
}
